import http from 'axios'
import store from './store'
import router from './router'

http.defaults.timeout = 20000

http.defaults.baseURL = 'https://web-gateway.newbeescm.com/b2b-app-web'

http.interceptors.request.use(
    config => {
        if(store.state.token) {
            config.headers.token = `${store.state.token}`
        }
        return config
    },
    err => {
    return Promise.reject(err)
  },
)

// http response 拦截器
http.interceptors.response.use(
    response => {
      return response
    },
    error => {
      if (error.response) {
        error.response
      }
      return Promise.reject(error.response.data)
    },
  )

export default http